$(function() {
	
	//订单详情展示
	initData();
	$(".sumbit .submit-order").on("tap",confirmPay);
	
	function initData(){
		var orderid = utilModule.getQueryString("orderid");
		if(utilModule.checkUndefined(orderid) != "") {
			var params = {
				id: orderid
			};
			speePhoneOrderModule.queryOrderDetail(params,function(callBack) {
				console.log(callBack);
				var result = callBack;
				$(".serviceTime").text(result.createTime);
				$(".payamount").text("¥ "+result.orderAmount+"元");
				$(".order-total span").text("¥ "+result.orderAmount+"元");
				$(".ordersn").text(result.orderSn);
			});
		}
	}
	
	//提交支付
	function confirmPay() {
		var orderid = utilModule.getQueryString("orderid");
		var params = {
			orderId: orderid
		}
		speePhoneOrderModule.submitPay(params,
			function(callBack) {
				var payInfo = callBack;
				if(payInfo != null) {
					onBridgeReady(payInfo);
				}
			});
	}
	
	//发起微信支付
	function onBridgeReady(result) {
		WeixinJSBridge.invoke('getBrandWCPayRequest', {
			"appId": result.appId, // 公众号名称，由商户传入
			"timeStamp": result.timeStamp, // 时间戳，自1970年以来的秒数
			"nonceStr": result.nonceStr, // 随机串
			"package": result.package, //package
			"signType": result.signType, // 微信签名方式：
			"paySign": result.paySign // 微信签名
		}, function(res) {
			if(res.err_msg == "get_brand_wcpay_request:ok") {
				sumitPaySuccess();
			} else if(res.err_msg == "get_brand_wcpay_request:cancel") {
				mui.alert('取消支付！', '提示');
			} else {
				mui.alert('支付失败！', '提示');
			}
		});
		
		function sumitPaySuccess() {
			var orderid = utilModule.getQueryString("orderid");
			mui.alert("支付成功!",function(){
				location.replace("rapidly-detail.html?orderType=4&orderid="+orderid);
			});
		}
	}
	
	
















});